'use strict';

/**
 * Config for the router
 */
angular.module('app')
    .run(['$rootScope', '$state', '$stateParams',
        function ($rootScope, $state, $stateParams) {
            $rootScope.$state = $state;
            $rootScope.$stateParams = $stateParams;
        }
    ])
    .config(
        ['$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {
                $urlRouterProvider
                    .otherwise('/app/home');
                $stateProvider
                    .state('app', {
                        abstract: true,
                        url: '/app',
                        templateUrl: 'tpl/app.html',
                        controller: 'HomeController',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(
                                        [
                                            'js/app/home/directives/Navigation.js',
                                            'js/app/home/services/NavigationService.js',
                                            'js/app/home/controllers/HomeController.js']);
                                }]
                        }
                    })
                    .state('app.home', {
                        url: '/home',
                        templateUrl: 'tpl/home.html',
                        controller: 'HomeController',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(
                                        ['js/app/home/directives/Navigation.js',
                                            'js/app/home/services/NavigationService.js',
                                            'js/app/home/controllers/HomeController.js']);
                                }]
                        }
                    })
                    .state('app.page', {
                        url: '/page',
                        template: '<div ui-view class="fade-in-down"></div>'
                    })
                    .state('app.page.profile', {
                        url: '/profile',
                        templateUrl: 'tpl/page_profile.html'
                    })
                    .state('app.page.search', {
                        url: '/search',
                        templateUrl: 'tpl/page_search.html'
                    })
                    // others
                    .state('lockme', {
                        url: '/lockme',
                        templateUrl: 'tpl/page_lockme.html'
                    })
                    .state('access', {
                        url: '/access',
                        template: '<div ui-view class="fade-in-right-big smooth"></div>'
                    })
                    .state('access.signin', {
                        url: '/signin',
                        templateUrl: 'tpl/user/page_signin.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/SigninFormController.js']);
                                }]
                        }
                    })
                    .state('access.signup', {
                        url: '/signup',
                        templateUrl: 'tpl/user/page_signup.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/SignupFormController.js']);
                                }]
                        }
                    })
                    .state('access.chooserole', {
                        url: '/chooserole',
                        templateUrl: 'tpl/user/choose_role.html',
                        resolve: {
                            deps: ['$ocLazyLoad', 'uiLoad', function ($ocLazyLoad, uiLoad) {
                                return uiLoad.load([
                                        'js/app/home/controllers/ChooseRoleController.js',
                                        'js/controllers/file-upload.js'])
                                    .then(function () {
                                        return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                    });
                            }]
                        }
                    })
                    .state('access.stylist', {
                        url: '/stylist',
                        templateUrl: 'tpl/user/page_stylist.html',
                        resolve: {
                            deps: ['$ocLazyLoad', 'uiLoad', function ($ocLazyLoad, uiLoad) {
                                return uiLoad.load([
                                        'js/app/home/controllers/StylistFormController.js',
                                        'js/controllers/file-upload.js','summernote/summernote.js','summernote/lang/summernote-zh-CN.min.js'])
                                    .then(function () {
                                        return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                    });
                            }]
                        }
                    })
                    .state('access.designer', {
                        url: '/designer',
                        templateUrl: 'tpl/user/page_designer.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/DesignerFormController.js',
                                        'js/controllers/file-upload.js','summernote/summernote.js','summernote/lang/summernote-zh-CN.min.js']);
                                }]
                        }
                    })
                    .state('access.chargeofstore', {
                        url: '/chargeofstore',
                        templateUrl: 'tpl/user/page_chargeofstore.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/ChargeOfStoreFormController.js',
                                        'js/controllers/file-upload.js']);
                                }]
                        }
                    })
                    .state('access.waitingaudit', {
                        url: '/waitingaudit',
                        templateUrl: 'tpl/user/waiting_audit.html'
                    })
                    .state('app.requisition_audit_list', {
                        url: '/requisition/audit/list',
                        templateUrl: 'tpl/user/requisition_audit_list.html',
                        resolve: {
                            deps: ['$ocLazyLoad','uiLoad',
                                function ($ocLazyLoad,uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/RequisitionAuditController.js',
                                        'js/app/home/service/RequisitionAuditService.js'
                                    ]).then(function () {
                                        return $ocLazyLoad.load(['ui.grid',
                                            'ui.grid.pagination',
                                            'ui.grid.resizeColumns',
                                            'ui.grid.moveColumns',
                                            'ui.grid.pinning',
                                            'ui.grid.exporter',
                                            'ui.grid.selection']);
                                    });
                                }]
                        }
                    })
                    .state('app.requisition_detail', {
                        url: '/requisition/detail/:pkId',
                        templateUrl: 'tpl/user/requisition_detail.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/RequisitionAuditController.js',
                                        'js/app/home/service/RequisitionAuditService.js','summernote/summernote.js',
                                        'summernote/lang/summernote-zh-CN.min.js'
                                    ]);
                                }]
                        }
                    })
                    .state('app.requisition_audit', {
                        url: '/requisition/audit/:pkId',
                        templateUrl: 'tpl/user/requisition_audit.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/app/home/controllers/RequisitionAuditController.js',
                                        'js/app/home/service/RequisitionAuditService.js'
                                    ]);
                                }]
                        }
                    })
                    .state('access.forgotpwd', {
                        url: '/forgotpwd',
                        templateUrl: 'tpl/page_forgotpwd.html'
                    })
                    .state('access.404', {
                        url: '/404',
                        templateUrl: 'tpl/page_404.html'
                    })
                    .state('app.goods', {
                        url: '/goods',
                        template: '<div ui-view class="fade-in-down"></div>'
                    })
                    .state('app.goods.release', {
                        url: '/goods_release',
                        templateUrl: 'tpl/goods/goods_release.html',
                        controller: 'NewGoodsController',
                        resolve: {
                            deps: [
                                '$ocLazyLoad', 'uiLoad', function ($ocLazyLoad, uiLoad) {
                                    return uiLoad.load([
                                        //'js/filters/propsFilter.js',
                                        'js/app/goods/controllers/NewGoodsController.js',
                                        'js/app/goods/service/goodsService.js',
                                        'js/app/goods/directive/pickColor.js',

                                        'js/controllers/file-upload.js'])
                                        .then(function () {
                                            return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                        });
                                }
                            ]
                        }
                    })
                    .state('app.goods.list', {
                        url: '/goods_list',
                        templateUrl: 'tpl/goods/goods_list.html',
                        resolve: {
                            deps: ['$ocLazyLoad', 'uiLoad',
                                function ($ocLazyLoad, uiLoad) {
                                    return uiLoad.load([
                                        'js/app/goods/controllers/GoodsListController.js'
                                    ]).then(function () {
                                        return $ocLazyLoad.load('ui.grid');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.pagination');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.resizeColumns');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.moveColumns');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.pinning');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.exporter');
                                    }).then(function () {
                                        return $ocLazyLoad.load('ui.grid.selection');
                                    });
                                }
                            ]
                        }
                    })
                    .state('app.order', {
                        url: '/order',
                        template: '<div ui-view class="fade-in-down"></div>'
                    })
                    .state('app.order.purchase_requisition_list', {
                    url: '/purchase',
                    templateUrl: 'tpl/order/order_list.html',
                    resolve: {
                        deps: ['$ocLazyLoad', 'uiLoad',
                            function ($ocLazyLoad, uiLoad) {
                                return uiLoad.load([
                                    'js/app/orders/controllers/PurchaseOrderController.js',
                                    'js/app/orders/service/PurchaseOrderService.js'
                                ]).then(function () {
                                    return $ocLazyLoad.load(['ui.grid',
                                        'ui.grid.pagination',
                                        'ui.grid.resizeColumns',
                                        'ui.grid.moveColumns',
                                        'ui.grid.pinning',
                                        'ui.grid.exporter',
                                        'ui.grid.selection']);
                                    });
                                }]
                            }
                        }).state('app.order.purchase_requisition_detail', {
                            url: '/purchase/detail/:orderId',
                            templateUrl: 'tpl/order/order.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/PurchaseOrderController.js',
                                            'js/app/orders/service/PurchaseOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                        });
                                    }]
                            }
                        }).state('app.order.transfer_requisition_list', {
                            url: '/transfer',
                            templateUrl: 'tpl/order/order_list_transfer.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/TransferOrderController.js',
                                            'js/app/orders/service/TransferOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['ui.grid',
                                                'ui.grid.pagination',
                                                'ui.grid.resizeColumns',
                                                'ui.grid.moveColumns',
                                                'ui.grid.pinning',
                                                'ui.grid.exporter',
                                                'ui.grid.selection']);
                                        });
                                    }]
                            }
                        }).state('app.order.transfer_requisition_detail', {
                            url: '/transfer/detail/:orderId',
                            templateUrl: 'tpl/order/order_transfer.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/TransferOrderController.js',
                                            'js/app/orders/service/TransferOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                        });
                                    }]
                            }
                        }).state('app.order.deliver_goods_invoices_list', {
                            url: '/deliver_goods',
                            templateUrl: 'tpl/order/order_list_deliver_goods.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/DeliverGoodsOrderController.js',
                                            'js/app/orders/service/DeliverGoodsOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['ui.grid',
                                                'ui.grid.pagination',
                                                'ui.grid.resizeColumns',
                                                'ui.grid.moveColumns',
                                                'ui.grid.pinning',
                                                'ui.grid.exporter',
                                                'ui.grid.selection']);
                                        });
                                    }]
                            }
                        }).state('app.order.deliver_goods_invoices_detail', {
                            url: '/deliver_goods/detail/:orderId',
                            templateUrl: 'tpl/order/order_deliver_goods.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/DeliverGoodsOrderController.js',
                                            'js/app/orders/service/DeliverGoodsOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                        });
                                    }]
                            }
                        }).state('app.order.deliver_goods_invoices_create', {
                            url: '/deliver_goods/create/:orderId',
                            templateUrl: 'tpl/order/invoice.html',
                            resolve: {
                                deps: ['$ocLazyLoad', 'uiLoad',
                                    function ($ocLazyLoad, uiLoad) {
                                        return uiLoad.load([
                                            'js/app/orders/controllers/DeliverGoodsOrderController.js',
                                            'js/app/orders/service/DeliverGoodsOrderService.js'
                                        ]).then(function () {
                                            return $ocLazyLoad.load(['textAngular', 'ui.select', 'angularFileUpload']);
                                        });
                                    }]
                            }
                        });
            }
        ]);